from requests_oauthlib import OAuth2Session

'''
获得 linked token
'''
client_id = '75wy732jxfp80j'
client_secret = '2e1efMFflb9hByi7'
scope = ['r_basicprofile', 'r_emailaddress', 'rw_company_admin', 'w_share']
url= 'https://www.linkedin.com/oauth/v2/authorization'
redirect_uri = 'https://knogent.com/oauth2'
oauth = OAuth2Session(client_id,redirect_uri = redirect_uri, state= 'DCEeHWf45A53sdfKef424')

authorization_url, state = oauth.authorization_url(
        url,
        # access_type and approval_prompt are Google specific extra
        # parameters.
        access_type="offline", approval_prompt="force")

print ('Please go to %s and authorize access.' % authorization_url)
authorization_response = input('Enter the full callback URL')
print(authorization_response)
token = oauth.fetch_token(
    'https://www.linkedin.com/oauth/v2/accessToken',
    authorization_response=authorization_response,
    client_secret=client_secret)
print(token)